package com.augurit.wf.bi.convert;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.augurit.wf.bi.web.form.WfActElemPrivDefForm;
import com.augurit.wf.bi.web.form.WfActPrinttplPrivDefForm;
import com.augurit.wf.bi.web.form.WfPageElementForm;
import com.augurit.wf.common.entity.WfActPrinttplPrivDef;

public class WfActPrinttplPrivDefConvertor {
	public static WfActPrinttplPrivDefForm convertVoToForm(WfActPrinttplPrivDef entity) {
		if(entity != null) {
			WfActPrinttplPrivDefForm form = new WfActPrinttplPrivDefForm();
			form.setId(entity.getId());
			form.setTemplateId(entity.getTemplateId());
			form.setVersion(entity.getVersion());
			form.setViewName(entity.getViewName());
			form.setActivityName(entity.getActivityName());
			form.setElementId(entity.getElementId());
			if(entity.getIsHidden() == null)
                form.setHidden(false);
            else
                form.setHidden(entity.getIsHidden().equals("1")?true:false);
            if(entity.getIsLock() == null)
                form.setLocked(false);
            else
                form.setLocked(entity.getIsLock().equals("1")?true:false);
			return form;
		}else
			return null;
	}
	
    public static WfActElemPrivDefForm convertVoToFkForm(WfActPrinttplPrivDef entity) {
        if(entity != null) {
            WfActElemPrivDefForm form = new WfActElemPrivDefForm();
            form.setId(entity.getId());
            form.setTemplateId(entity.getTemplateId());
            form.setViewName(entity.getViewName());
            form.setActivityName(entity.getActivityName());
            form.setElementId(entity.getElementId());
            form.setVersion(entity.getVersion().intValue());
            if(entity.getIsHidden() == null)
                form.setHidden(false);
            else
                form.setHidden(entity.getIsHidden().equals("1")?true:false);
            if(entity.getIsLock() == null)
                form.setLocked(false);
            else
                form.setLocked(entity.getIsLock().equals("1")?true:false);
            return form;
        }else
            return null;
    }

    public static WfActPrinttplPrivDefForm convertFormToForm(WfActElemPrivDefForm fkform) {
        if(fkform != null) {
            WfActPrinttplPrivDefForm form = new WfActPrinttplPrivDefForm();

            form.setId(fkform.getId());
            form.setTemplateId(fkform.getTemplateId());
            form.setViewName(fkform.getViewName());
            form.setActivityName(fkform.getActivityName());
            form.setElementId(fkform.getElementId());
            form.setVersion(fkform.getVersion().longValue());
            form.setHidden(fkform.isHidden());
            form.setLocked(fkform.isLocked());
            return form;
        }else
            return null;
    }
	
	public static void convertFormToVo(WfActPrinttplPrivDefForm form, WfActPrinttplPrivDef entity) {
		if(entity != null && form != null) {
			entity.setId(form.getId());
			entity.setTemplateId(form.getTemplateId());
			entity.setVersion(form.getVersion());
			if(form.getViewName() != null && form.getViewName().trim().length() > 0)
				entity.setViewName(form.getViewName().trim());
			if(form.getActivityName() != null && form.getActivityName().trim().length() > 0)
				entity.setActivityName(form.getActivityName().trim());
			entity.setElementId(form.getElementId());
            entity.setIsHidden(form.isHidden()?WfPageElementForm.HIDDEN :WfPageElementForm.NOT_HIDDEN);
            entity.setIsLock(form.isLocked()?WfPageElementForm.LOCKED: WfPageElementForm.NOT_LOCKED);
		}
	}
	
	public static List<WfActPrinttplPrivDefForm> convertVoListToFormList(List<WfActPrinttplPrivDef> wfActPrinttplPrivDefList) {
		if(wfActPrinttplPrivDefList != null && wfActPrinttplPrivDefList.size() > 0) {
			List<WfActPrinttplPrivDefForm> wfActPrinttplPrivDefFormList = new ArrayList();
			for(int i=0; i<wfActPrinttplPrivDefList.size(); i++) {
				wfActPrinttplPrivDefFormList.add(convertVoToForm(wfActPrinttplPrivDefList.get(i)));
			}
			return wfActPrinttplPrivDefFormList;
		}
		return null;
	}
	
	public static List<Map> convertVoListToMapList(List<WfActPrinttplPrivDef> wfActPrinttplPrivDefList) {
		if(wfActPrinttplPrivDefList != null && wfActPrinttplPrivDefList.size() > 0) {
			List<Map> mapList = new ArrayList();
			for(int i=0; i<wfActPrinttplPrivDefList.size(); i++) {
				WfActPrinttplPrivDef entity = wfActPrinttplPrivDefList.get(i);
				Map<String, String> map = new HashMap();

				map.put("id", entity.getId() == null ? "" : entity.getId().toString());
				map.put("templateId", entity.getTemplateId() == null ? "" : entity.getTemplateId().toString());
				map.put("version", entity.getVersion() == null ? "" : entity.getVersion().toString());
				map.put("viewName", entity.getViewName());
				map.put("activityName", entity.getActivityName());
				map.put("elementId", entity.getElementId() == null ? "" : entity.getElementId().toString());
				map.put("isHidden", entity.getIsHidden());
				map.put("isLock", entity.getIsLock());
				
				mapList.add(map);
			}
			return mapList;
		}
		return null;
	}
	
	public static List<WfActPrinttplPrivDef> convertFormListToVoList(List<WfActPrinttplPrivDefForm> wfActPrinttplPrivDefFormList) {
		if(wfActPrinttplPrivDefFormList != null && wfActPrinttplPrivDefFormList.size() > 0) {
			List<WfActPrinttplPrivDef> wfActPrinttplPrivDefList = new ArrayList();
			for(int i=0; i<wfActPrinttplPrivDefFormList.size(); i++) {
				WfActPrinttplPrivDef wfActPrinttplPrivDef = new WfActPrinttplPrivDef();
				convertFormToVo(wfActPrinttplPrivDefFormList.get(i), wfActPrinttplPrivDef);
				wfActPrinttplPrivDefList.add(wfActPrinttplPrivDef);
			}
			return wfActPrinttplPrivDefList;
		}
		return null;
	}
}